package sctu.edu.java.year2016.team08.zengshenjing.day20160611.chapter11_3;

/**
 * Created by Administrator on 2016/6/11.
 * 创建一个Conputer类，计算两个数的最大公约数，如果输入负整数就抛出自定义异常
 */
    public class Computer extends Exception{
        public int GetGcd(int a,int b) throws Exception{
            if(a<0||b<0){
                throw new Exception();
            }
            else{

                if(a<b){
                    int i;
                    i=b;
                    b=a;
                    a=i;
                }
                else
                    while (a % b != 0) {
                        int temp = a % b;
                        a = b;
                        b = temp;
                    }
            }
            System.out.println("最大公约数"+b);
            return b;
        }
    }

